package com.github.dunr;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class Index {

    @Autowired
    LoadBalancerClient loadBalancerClient;
    @Autowired
    RestTemplate restTemplate;

    @RequestMapping("customer/other/hello")
    public String hello(){
//        ServiceInstance serviceInstance = loadBalancerClient.choose("eureka-customer");
//        String url = "http://" + serviceInstance.getHost() + ":" + serviceInstance.getPort() + "/customer/hello";
        String url = "http://eureka-customer/customer/hello";
        System.out.println(url);
        return restTemplate.getForObject(url,String.class);
    }
}
